
<%@ page import="les.Integrante" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <g:set var="entityName" value="${message(code: 'integrante.label', default: 'Integrante')}" />
        <title>Listar Integrantes</title>
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}">Inicio</a></span>
            <g:if test="${session.usuarioLogado.tipo in ['Administrador', 'Jota']}">
            	<span class="menuButton"><g:link class="create" action="create">Novo Integrante</g:link></span>
            	<span class="menuButton"><g:link action="experienciasPassadas">Ver Experi&ecirc;ncias Passadas</g:link></span>
            </g:if>
        </div>
        <div class="body">
            <h1>Lista de Integrantes</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            
            <br />
            <g:form method="post" >
            	Buscar por nome: <g:textField name="buscaNome" value="${parametros?.buscaNome}" size="30" /> <g:actionSubmit class="list" action="list" value="Buscar" id="buscar" />
            </g:form>
            <g:form method="post" >
            	<g:hiddenField name="buscaTudo" value="1" />	
            	<g:actionSubmit class="list" action="list" value="Listar todos" id="listarTodos" />
            </g:form>
            
            
            <br />
           
            <div class="list">
                <table>
                    <thead>
                        <tr>
                        
                            <g:sortableColumn property="nome" title="${message(code: 'integrante.nome.label', default: 'Nome')}" />
                        
                            <g:sortableColumn property="sexo" title="${message(code: 'integrante.sexo.label', default: 'Sexo')}" />
                            
                            <th>
                            	Cônjuge
                            </th>
                            
                            <th>
                            	Telefone(s)
                            </th>
                            
                            <th>
                            	E-mail
                            </th>
                            
                            <th>
                            	Deletar
                            </th>
                        
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${integranteInstanceList}" status="i" var="integranteInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        
                            <td><g:link action="show" id="${integranteInstance.id}">${fieldValue(bean: integranteInstance, field: "nome")}</g:link></td>
                        
                            <td>${fieldValue(bean: integranteInstance, field: "sexo")}</td>
                        
                        	<td>${integranteInstance.conjuge?.nome}</td>
                        
                        	<td>
                        	<%
							separador = ""
							for (String telefone : integranteInstance.telefones) {
								out << separador + telefone;
								separador = " / ";
							}
							%>
							</td>
							
							<td>${fieldValue(bean: integranteInstance, field: "email")}</td>

							<td>
								<g:form>
                    			<g:hiddenField name="id" value="${integranteInstance?.id}" />
                    			<span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Voce tem certeza?')}');" /></span>
                				</g:form>	
							</td>							
                        
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            <g:if test="${!parametros.buscaTudo}">
            	<div class="paginateButtons">
                	<g:paginate total="${integranteInstanceTotal}" />
            	</div>
            </g:if>
            
            &nbsp;
        </div>
    </body>
</html>
